package day1_12.other;
// 需求: 复制数组,索引从from开始到to结束
public class CopyArray {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8,9};
        int[] copy = CopyArr(arr,4,6);;
        for (int i = 0; i < copy.length; i++) {
            System.out.print(copy[i] + " ");
        }

    }
    // 返回值为int型的数组
    public static int[] CopyArr(int[] arr,int from ,int to) {
        int[] newArr = new int[to - from];
        int index = 0;
        for (int i = from; i < to; i++) {
            newArr[index] = arr[i];
            index ++;
        }
        return newArr;
    }
}
